package cadc.ping;

import com.windpicker.common.utils.Encoder;

import cadc.actions.UserAction;
import cadc.daos.AccountDao;
import cadc.models.Account;

@SuppressWarnings("serial")
public class DoLogin extends UserAction {
private AccountDao accountDao;
	
	public String execute(){
		Account a = accountDao.findAccountByName(super.getAccount().getName());
		if(a==null || a.getId()==0){
			this.addActionError("用户名不存在");
			return INPUT;
		}else if(a.getPassword().equals(Encoder.encryptMD5(super.getAccount().getPassword()))){
			super.getAccount().setId(a.getId());
			super.getAccount().setRegistrationTime(a.getRegistrationTime());
			super.getAccount().setLoggedin(true);
			return "home";
		}else{
			this.addActionError("密码错误");
			return INPUT;
		}
	}

	public void setAccountDao(AccountDao accountDao) {
		this.accountDao = accountDao;
	}
	public AccountDao getAccountDao() {
		return accountDao;
	}
}
